package com.sakura.taos.tool.manipulator.model;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;

import java.util.Date;
import java.util.Map;
import java.util.Set;

import static com.sakura.taos.tool.manipulator.conf.ConstantConf.DATA_BASE_GROUP_SEPARATOR;

/**
 * 数据库信息
 *
 * @Author: 贺坤
 * @Date: 2021/1/27 21:38
 */
@Data
public class DataBaseNews {

    private String name;
    private Long createdTime;
    private Integer ntables;
    private Integer vgroups;
    private Integer replica;
    private Integer quorum;
    private Integer days;
//    @TableField("\"keep1,keep2,keep(D)\"")   //不起作用 ,改用map接受,手动封装
    private String keep1_keep2_keep_D;
//    @TableField("\"cache(MB)\"")      //不起作用 ,改用map接受,手动封装
    private Integer cache_MB;
    private Integer blocks;
    private Integer minrows;
    private Integer maxrows;
    private Integer wallevel;
    private Integer fsync;
    private Integer comp;
    private Integer cachelast;
    private String precision;
    private Integer update;
    private String status;
    /**
     * 给库选择时候前端的缓存值
     */
    private String dsName;

    public DataBaseNews(String dsName,Map<String,Object> map) {
        this.dsName = dsName+DATA_BASE_GROUP_SEPARATOR+map.get("name").toString();
        Set<String> keySet = map.keySet();
        for (String key:keySet ) {
            switch (key){
                case "name":this.name= map.get(key).toString() ; break;
                case "created_time":this.createdTime =  Long.valueOf(map.get(key).toString()) ; break;
                case "ntables":this.ntables = Integer.valueOf( map.get(key).toString() ); break;
                case "vgroups":this.vgroups = Integer.valueOf( map.get(key).toString() ); break;
                case "replica":this.replica = Integer.valueOf( map.get(key).toString() ); break;
                case "quorum":this.quorum = Integer.valueOf( map.get(key).toString() ); break;
                case "days":this.days = Integer.valueOf( map.get(key).toString() ); break;
                case "keep1,keep2,keep(D)":this.keep1_keep2_keep_D =  map.get(key).toString() ; break;
                case "cache(MB)":this.cache_MB = Integer.valueOf( map.get(key).toString()) ; break;
                case "blocks":this.blocks = Integer.valueOf( map.get(key).toString()) ; break;
                case "minrows":this.minrows = Integer.valueOf( map.get(key).toString()) ; break;
                case "maxrows":this.maxrows = Integer.valueOf( map.get(key).toString()) ; break;
                case "wallevel":this.wallevel = Integer.valueOf( map.get(key).toString()) ; break;
                case "fsync":this.fsync = Integer.valueOf( map.get(key).toString()) ; break;
                case "comp":this.comp = Integer.valueOf( map.get(key).toString()) ; break;
                case "cachelast":this.cachelast = Integer.valueOf( map.get(key).toString()) ; break;
                case "precision":this.precision =  map.get(key).toString() ; break;
                case "update":this.update = Integer.valueOf(  map.get(key).toString() ); break;
                case "status":this.status =  map.get(key).toString() ; break;
            }
        }
    }
}
